package cn.tansanqinger.service.catalogue.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.tansanqinger.dao.sql.catalogue.CatalogueDisposeMessage;
import cn.tansanqinger.dao.sql.knowledge.KnowledgeSqlDaoImpl;
import cn.tansanqinger.pojo.Catalogue;
import cn.tansanqinger.service.catalogue.ICatalogueService;

@Service
public class CatalogueServiceImpl implements ICatalogueService{

	@Autowired
	public CatalogueDisposeMessage message;
	@Autowired
	private KnowledgeSqlDaoImpl impl;
	
	@Override
	public boolean insert(Catalogue catalogue) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean deleteCno_Ctop(Integer cno) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean deleteCno(Integer cno) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean updateCno(Integer cno, Integer ncno) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean updateSingle(Catalogue catalogue) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public List<Catalogue> selectAll() {
		return message.selectAll();
	}

	@Override
	public Map<String, Object> selectOnes(String ctop) {
		List<Object> resultList = new ArrayList<Object>();
		Map<String, Object> resultMap = new HashMap<String, Object>();
		List<Catalogue> firstList = message.selectOnes(Integer.parseInt("100000"+ctop));
		for (int i = 0; i < firstList.size(); i++) {
			resultList.add(firstList.get(i));
			List<Catalogue> list = message.selectOnes(firstList.get(i).getCno());
			if(!list.isEmpty()&&i==0) {
				if(list.get(0).getCpath().matches("\\d+")) {
					resultMap.put("knowledge", impl.selectOne(Integer.parseInt(list.get(0).getCpath())));
				}
			}
			resultList.add(list);
		}
		resultMap.put("resultList", resultList);
		return resultMap;
	}

	@Override
	public Catalogue selectOne(Integer cno) {
		
		return null;
	}
}
